using System;
using System.Data.Entity.ModelConfiguration;
using System.Data.Common;
using System.Data.Entity;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using DataAccess.Entities;

namespace DataAccess.Mapping
{
	public class OrganizationTempMap : EntityTypeConfiguration<OrganizationTemp>
	{
		public OrganizationTempMap()
		{
			// Primary Key
			this.HasKey(t => t.Id);

			// Properties
			this.Property(t => t.Name)
				.IsRequired()
				.HasMaxLength(100);
				
			this.Property(t => t.Address)
				.IsRequired()
				.HasMaxLength(200);
				
			this.Property(t => t.Zipcode)
				.HasMaxLength(10);
				
			this.Property(t => t.Site)
				.HasMaxLength(100);
				
			this.Property(t => t.Email)
				.HasMaxLength(50);
				
			this.Property(t => t.Tel)
				.HasMaxLength(20);
				
			this.Property(t => t.Domain)
				.HasMaxLength(100);
				
			this.Property(t => t.LatLng)
				.HasMaxLength(20);
				
			this.Property(t => t.DeleteFlag)
				.IsFixedLength()
				.HasMaxLength(1);
				
			// Table & Column Mappings
			this.ToTable("OrganizationTemp");
			this.Property(t => t.Id).HasColumnName("Id");
			this.Property(t => t.ParentId).HasColumnName("ParentId");
			this.Property(t => t.Name).HasColumnName("Name");
			this.Property(t => t.Address).HasColumnName("Address");
			this.Property(t => t.Zipcode).HasColumnName("Zipcode");
			this.Property(t => t.Site).HasColumnName("Site");
			this.Property(t => t.Email).HasColumnName("Email");
			this.Property(t => t.Tel).HasColumnName("Tel");
			this.Property(t => t.CategoryId).HasColumnName("CategoryId");
			this.Property(t => t.IndustryId).HasColumnName("IndustryId");
			this.Property(t => t.KindId).HasColumnName("KindId");
			this.Property(t => t.SizeId).HasColumnName("SizeId");
			this.Property(t => t.AreaId).HasColumnName("AreaId");
			this.Property(t => t.Domain).HasColumnName("Domain");
			this.Property(t => t.LatLng).HasColumnName("LatLng");
			this.Property(t => t.TotalMark).HasColumnName("TotalMark");
			this.Property(t => t.DeleteFlag).HasColumnName("DeleteFlag");
			this.Property(t => t.CreateDate).HasColumnName("CreateDate");
			this.Property(t => t.UpdateDate).HasColumnName("UpdateDate");
			this.Property(t => t.CreateBy).HasColumnName("CreateBy");
			this.Property(t => t.UpdateBy).HasColumnName("UpdateBy");

			// Relationships
			this.HasOptional(t => t.Area)
				.WithMany(t => t.OrganizationTemps)
				.HasForeignKey(d => d.AreaId);
				
			this.HasOptional(t => t.Category)
				.WithMany(t => t.OrganizationTemps)
				.HasForeignKey(d => d.CategoryId);
				
			this.HasOptional(t => t.Industry)
				.WithMany(t => t.OrganizationTemps)
				.HasForeignKey(d => d.IndustryId);
				
			this.HasOptional(t => t.Organization)
				.WithMany(t => t.OrganizationTemps)
				.HasForeignKey(d => d.ParentId);
				
			this.HasOptional(t => t.Size)
				.WithMany(t => t.OrganizationTemps)
				.HasForeignKey(d => d.SizeId);
				
		}
	}
}

